# clean environment
rm(list=ls())

# load packages
library(ggplot2)

# load data sets with articles
de_rwe = read.csv("nexis_de_rwe.csv")
de_lwe = read.csv("nexis_de_lwe.csv")
us_rwe = read.csv("nexis_usa_rwe.csv")
us_lwe = read.csv("nexis_usa_lwe.csv")
uk_rwe = read.csv("nexis_uk_rwe.csv")
uk_lwe = read.csv("nexis_uk_lwe.csv")

# assign country names
de_rwe$country = "Germany"
de_lwe$country = "Germany"
us_rwe$country = "USA"
us_lwe$country = "USA"
uk_rwe$country = "UK"
uk_lwe$country = "UK"

# assign extremism type
de_rwe$extremism = "Right-wing extremism"
de_lwe$extremism = "Left-wing extremism"
us_rwe$extremism = "Right-wing extremism"
us_lwe$extremism = "Left-wing extremism"
uk_rwe$extremism = "Right-wing extremism"
uk_lwe$extremism = "Left-wing extremism"

# combine data frames
dat = rbind.data.frame(de_rwe, de_lwe, us_rwe, us_lwe, uk_rwe, uk_lwe)

# get year
dat$year = substring(dat$Berichterstattung.im.Laufe.der.Zeit, 1, 4)
dat$year = as.numeric(dat$year)

# country levels 
dat$country = factor(dat$country, levels=c("Germany", "USA", "UK"))

# plot
ggplot(data=dat[dat$year < 2025,], aes(x=year, y=Abdeckung, group=extremism, color=extremism, shape=extremism)) +
  geom_point() +
  geom_line() +
  facet_wrap(~country, scales="free") +
  theme_bw() +
  xlab("Year") + ylab("Number of articles") +
  theme(panel.grid =element_blank(), legend.position = "bottom",
        text = element_text(size=15),
        axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_color_manual(values = c("firebrick", "dodgerblue"), name="Type of Extremism", labels=c("LWE", "RWE")) +
  scale_shape_manual(values=c(16, 17), name="Type of Extremism", labels=c("LWE", "RWE"))

ggsave("Fig1_1.pdf", width=7, height=5)
